/*     */ package com.newcrm.db;
/*     */ 
/*     */ import com.newcrm.exception.DBException;
/*     */ import java.sql.Connection;
/*     */ import java.sql.SQLException;
/*     */ import java.util.Map;
/*     */ import org.apache.commons.dbutils.DbUtils;
/*     */ import org.apache.commons.dbutils.MyMapHandler;
/*     */ import org.apache.commons.dbutils.QueryRunner;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class CompanyAccessManager
/*     */ {
/*  17 */   private static Logger logger = Logger.getLogger(CompanyAccessManager.class
/*  18 */     .getName());
/*     */ 
/*     */   public Map<String, Object> getAllDetail()
/*     */   {
/*  26 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*  27 */     if (conn == null) {
/*  28 */       return null;
/*     */     }
/*     */ 
/*  31 */     QueryRunner runner = new QueryRunner();
/*     */     try {
/*  33 */       return (Map)runner.query(conn, "SELECT * FROM T_Company_Access_Info", 
/*  34 */         new MyMapHandler());
/*     */     } catch (SQLException e) {
/*  36 */       logger.warn("get company access Url detail failed", e);
/*     */     } finally {
/*     */       try {
/*  39 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/*  41 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/*  44 */     return null;
/*     */   }
/*     */ 
/*     */   public Map<String, Object> getDetail(int companyId)
/*     */   {
/*  54 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*  55 */     if (conn == null) {
/*  56 */       return null;
/*     */     }
/*     */ 
/*  59 */     QueryRunner runner = new QueryRunner();
/*     */     try {
/*  61 */       return (Map)runner.query(conn, "SELECT * FROM T_Company_Access_Info WHERE CompanyId = ?", 
/*  62 */         new MyMapHandler(), new Object[] { Integer.valueOf(companyId) });
/*     */     } catch (SQLException e) {
/*  64 */       logger.warn("get company access Url detail failed", e);
/*     */     } finally {
/*     */       try {
/*  67 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/*  69 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/*  72 */     return null;
/*     */   }
/*     */ 
/*     */   public int add(int companyId, String accessId, String accessPwd, String email)
/*     */     throws SQLException, DBException
/*     */   {
/*  88 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*  89 */     if (conn == null) {
/*  90 */       throw new DBException();
/*     */     }
/*  92 */     QueryRunner runner = new QueryRunner();
/*     */     try
/*     */     {
/*  95 */       return runner.update(conn, "INSERT INTO T_Company_Access_Info (CompanyId,AccessId,AccessPwd,CreateDate,UpdateDate) VALUES (?,?,?,NOW(),NOW()) ON DUPLICATE KEY UPDATE AccessId = ?, AccessPwd = ?, UpdateDate = NOW()", new Object[] { Integer.valueOf(companyId), 
/*  96 */         accessId, accessPwd, accessId, accessPwd });
/*     */     } finally {
/*     */       try {
/*  99 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/* 101 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   public int update(int companyId, String accessId, String accessPwd)
/*     */     throws SQLException
/*     */   {
/* 117 */     Connection conn = ConnectionManager.getInstance().getConnection();
/* 118 */     if (conn == null) {
/* 119 */       return 0;
/*     */     }
/* 121 */     QueryRunner runner = new QueryRunner();
/*     */     try
/*     */     {
/* 124 */       int result = runner.update(conn, "UPDATE T_Company_Access_Info SET AccessId = ?, AccessPwd = ?, UpdateDate = NOW() WHERE CompanyId = ?", new Object[] { 
/* 125 */         accessId, accessPwd, Integer.valueOf(companyId) });
/*     */       int i;
/* 128 */       if (result == 0) {
/* 129 */         return runner.update(conn, "INSERT INTO T_Company_Access_Info (CompanyId,AccessId,AccessPwd,CreateDate,UpdateDate) VALUES (?,?,?,NOW(),NOW()) ON DUPLICATE KEY UPDATE AccessId = ?, AccessPwd = ?, UpdateDate = NOW()", new Object[] { 
/* 130 */           Integer.valueOf(companyId), accessId, accessPwd, accessId, accessPwd });
/*     */       }
/* 132 */       return result;
/*     */     } finally {
/*     */       try {
/* 135 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/* 137 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.db.CompanyAccessManager
 * JD-Core Version:    0.6.1
 */